<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vuex使用</title>
</head>
<body>
<id id="app">
    <h1>Vuex使用</h1>
    <button @click="increment">+</button>
    <button @click="decrement">-</button>
    <p>{{ count }}</p>
</id>
</body>
<script src="../js/vue.js"></script>
<script >
// import Vuex from 'vuex';
require('vuex');

Vue.use(Vuex);
var store = new Vuex.Store({
    state: {
        count: 0
    },
    mutations: {
        increment(state) {
            state.count++
        },
        decrement(state) {
            state.count--
        }
    }
})
var vm = new Vue({
    el: '#app',
    store,
    computed: {
        count() {
            return this.$store.state.count
        }
    },
    methods: {
        increment() {
            this.$store.commit('increment')
        },
        decrement() {
            this.$store.commit('decrement')
        }
    }
})
</script>
</html>